<?php
/**
 * Junction_Class_Class
 * 
 * Models a class
 * 
 * @author Patrick J. Mizer <patrick.mizer@gmail.com>
 */
using("Junction_Class_Field");

class Junction_Class_Class 
{
	/**
	 * Class's name
	 * 
	 * @var string
	 */
	private $_name;
	
	/**
	 * Class's fields
	 * 
	 * @var array
	 */
	private $_fields;
	
	/**
	 * Class's ID
	 * 
	 * @var string
	 */
	private $_id;
	
	/**
	 * Class's table
	 * 
	 * @var Junction_Sql_Table
	 */
	private $_table;
	
	/**
	 * Number of fields
	 * 
	 * @var int
	 */
	private $_numFields;
	
	/**
	 * Junction_Class_Class Constructor
	 * 
	 * @param string name
	 * @param string id
	 * @param Junction_Sql_Table table
	 */
    public function __construct($name, $id, $table) 
    {
    	$this->_name 		= $name;
    	$this->_id 			= $id;
    	$this->_table		= $table;
    	$this->_numFields 	= 0;
    }
    
    /**
     * Getter for class name
     * 
     * @return string
     */
    public function getName()
    {
    	return $this->_name;
    }
    
    /**
     * Getter for table
     * 
     * @return Junction_Sql_Table
     */
    public function getTable()
    {
    	return $this->_table;
    }
    
    /**
     * Getter for class's ID field
     * 
     * @return Junction_Class_Field
     */
    public function getIdField()
    {
    	return $this->_fields[$this->_id];
    }
    
    /**
     * Getter for field
     * 
     * @return Junction_Class_Field
     */
    public function getField($key)
    {
    	return $this->_fields[$key];
    }
    
    /**
     * Getter for all fields
     * 
     * @return array
     */
    public function getFields()
    {
    	return $this->_fields;
    }
    
    /**
     * Getter for number of fields
     * 
     * @return int
     */
    public function getNumFields()
    {
    	return $this->_numFields;
    }
    
    /**
     * Attribute field to Class
     * 
     * @param string name
     * @param Junction_Sql_Column
     * @return void
     */
    public function addField($name, $column)
    {
    	if(!isset($this->_fields[$name])){
    		++ $this->_numFields;
    	}
    	$this->_fields[$name] = new Junction_Class_Field($name, $column, $this);
    }
    
}
?>